package jsqlite;

import java.io.BufferedReader;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.codehaus.jackson.util.MinimalPrettyPrinter;

/* loaded from: classes2.dex */
public class SQLRestore {
    Database db;
    BufferedReader is;

    public SQLRestore(InputStream inputStream, Database database) {
        this.is = new BufferedReader(new InputStreamReader(inputStream));
        this.db = database;
    }

    public void restore() throws Exception {
        String str;
        String str2;
        loop0: while (true) {
            str = null;
            do {
                try {
                    str2 = this.is.readLine();
                } catch (EOFException unused) {
                    str2 = null;
                } catch (IOException e) {
                    throw new Exception("I/O error: " + e);
                }
                if (str2 == null) {
                    break loop0;
                } else if (str == null) {
                    str = str2;
                } else {
                    str = String.valueOf(str) + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR + str2;
                }
            } while (!Database.complete(str));
            this.db.exec(str, null);
        }
        if (str == null) {
            return;
        }
        throw new Exception("Incomplete SQL: " + str);
    }
}
